package com.flymobi.service;

import java.util.ArrayList;
import java.util.List;

import com.flymobi.fw.modules.CommonService;
import com.flymobi.fw.util.StringUtil;
import com.flymobi.po.SpChongzhiLog;
import com.flymobi.vo.SpChongzhiLogSearchVo;

public class SpChongzhiLogService extends CommonService {
	public List<SpChongzhiLog> list(SpChongzhiLogSearchVo param, int startRow, int pagePerSize) {
		String hql = "from SpChongzhiLog m where 1=1 ";
		List<Object> paramList = new ArrayList<Object>();
		if (param != null) {
			if (!StringUtil.isEmpty(param.getSpName())
					&& param.getSpName().trim().length() > 0) {
				hql += " and m.spName like ?";
				paramList.add("%"+param.getSpName()+"%");
			}
			if (param.getEnd() != null) {
				hql += " and m.savetime<?";
				paramList.add(param.getEnd());
			}
			if (param.getStart() != null) {
				hql += " and m.savetime>?";
				paramList.add(param.getStart());
			}
		}
		hql += " order by m.id desc";
		System.out.println("hql:" + hql);
		System.out.println("param:" + param.toString());
		return dao.find(SpChongzhiLog.class, hql, paramList, startRow, pagePerSize);
	}

	public Long getCount(SpChongzhiLogSearchVo param) {
		String hql = "select count(*) from SpChongzhiLog m where 1=1 ";
		List<Object> paramList = new ArrayList<Object>();
		if (param != null) {
			if (!StringUtil.isEmpty(param.getSpName())
					&& param.getSpName().trim().length() > 0) {
				hql += " and m.spName like ?";
				paramList.add("%"+param.getSpName()+"%");
			}
			if (param.getEnd() != null) {
				hql += " and m.savetime<?";
				paramList.add(param.getEnd());
			}
			if (param.getStart() != null) {
				hql += " and m.savetime>?";
				paramList.add(param.getStart());
			}
		}
		return dao.getCount(hql, paramList);
	}

	public void save(SpChongzhiLog users) {
		dao.save(users);
	}

	public SpChongzhiLog load(String id) {
		return dao.load(SpChongzhiLog.class, new Long(id));
	}

	public SpChongzhiLog get(String id) {
		return dao.get(SpChongzhiLog.class, new Long(id));
	}

	public void delete(String id) {
		dao.delete(this.get(id));
	}
}
